<template>
    <div class='approval'>
      <el-card class="box-card" style="margin-top: 110px;overflow:scroll;">
        <div class="head-title2">
          <div class='title'>
            {{$t('achievements.title1')}}
          </div>
          <div class="info">
            <el-tooltip placement="left">
              <div slot="content">
                {{define}}
              </div>
              <div class="btns"></div>
            </el-tooltip>
          </div>
        </div>
        <div class='menu-search'> 
            <div class='menu-title'>
              <!-- 时间 -->
              <div class='searchItem searchItem-date'>
                <span>{{$t('approvalDetail.riskTime')}}</span>
                <el-date-picker
                  size='small'
                  v-model="listQuery.dateBegin"
                  type="date"
                  value-format="yyyy-MM-dd"
                  :placeholder="$t('rule.beginDate')"
                  :picker-options="startDatePicker"
                ></el-date-picker>
                <b>{{$t('approval.go')}}</b>
                <el-date-picker
                  size='small'
                  v-model="listQuery.dateEnd"
                  type="date"
                  value-format="yyyy-MM-dd"
                  :placeholder="$t('rule.endDate')"
                  :picker-options="endDatePicker"
                ></el-date-picker>
              </div>
              <!-- APP渠道 -->
              <div class="searchItem">
                <span>{{$t('ElectricChannel.AppChannel')}}</span>
                <el-select v-model="listQuery.channel" size="small">
                  <el-option
                    v-for="item in appChannel"
                    :key="item.channel"
                    :label="item.org_name"
                    :value="item.channel"
                  ></el-option>
                </el-select>
              </div>
              <div class='menu-title-btn'>
                  <button type='button' @click='search'>
                      {{$t('btn.query')}}
                  </button>
                  <button type="button" @click="reset">
                      {{$t('btn.reset')}}
                  </button>
              </div>
            </div>
        </div>
      </el-card>
        <el-card class='box-card' style="margin-top: 10px;margin-bottom: 20px;">
          <div class='title'>
              {{$t('approval.title2')}}
          </div>
          <el-table
              :sum-text="$t('ApprReport.total')"
              v-loading="listLoading"
              ref='multipleTable'
              :data='tableData'
              tooltip-effect='dark'
              style='width: 100%; margin-top: 5px;'
              @selection-change='handleSelectionChange'
              border
              size='mini'>
              <!-- 日期 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='crtTime'
              width="140"
              :label="$t('overdueData.time')">
              </el-table-column>
              <!-- 机审案件数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='machineApprovalCount'
              width="160"
              :label="$t('EfficiencyAppr.MachineAuditCase')">
              </el-table-column>
              <!-- 机审通过数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='machinePassCount'
              width="160"
              :label="$t('EfficiencyAppr.MachineAuditPass')">
              </el-table-column>
              <!-- 机审放款数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='machineCashoutCount'
              width="160"
              :label="$t('EfficiencyAppr.MachineAuditLoan')">
              </el-table-column>
              <!-- 机审拒绝数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='machineRefuseCount'
              width="160"
              :label="$t('EfficiencyAppr.MachineAuditRefuse')">
              </el-table-column>
              <!-- 初审案件数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='firstApprovalCount'
              width="160"
              :label="$t('EfficiencyAppr.firstTrialCase')">
              </el-table-column>
              <!-- 初审在库案件总数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='firstPondCount'
              width="160"
              :label="$t('EfficiencyAppr.firstLibraryCase')">
              </el-table-column>
              <!-- 初审通过数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='firstPassCount'
              width="160"
              :label="$t('EfficiencyAppr.firstTrialPass')">
              </el-table-column>
              <!-- 初审拒绝数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='fistRefuseCount'
              width="160"
              :label="$t('EfficiencyAppr.firstTrialRefuse')">
              </el-table-column>
              <!-- 复审案件数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='complexApprovalCount'
              width="160"
              :label="$t('EfficiencyAppr.reviewCase')">
              </el-table-column>
              <!-- 复审在库案件总数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='complexPondCount'
              width="160"
              :label="$t('EfficiencyAppr.reviewLibraryCase')">
              </el-table-column>
              <!-- 复审通过数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='complexPassCount'
              width="160"
              :label="$t('EfficiencyAppr.reviewPass')">
              </el-table-column>
              <!-- 复审拒绝数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='complexRefuseCount'
              width="160"
              :label="$t('EfficiencyAppr.reviewRefuse')">
              </el-table-column>
              <!-- 终审案件数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='finallApprovalCount'
              width="160"
              :label="$t('EfficiencyAppr.FinalJudgmentCase')">
              </el-table-column>
              <!-- 终审在库案件总数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='finallPondCount'
              width="160"
              :label="$t('EfficiencyAppr.FinalLibraryCase')">
              </el-table-column>
              <!-- 终审通过数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='finallPassCount'
              width="160"
              :label="$t('EfficiencyAppr.FinalJudgmentPass')">
              </el-table-column>
              <!-- 终审拒绝数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='finallRefuseCount'
              width="160"
              :label="$t('EfficiencyAppr.FinalJudgmentRefuse')">
              </el-table-column>
              <!-- 放款笔数 -->
              <el-table-column
              header-align='center'
              align='center'
              prop='successCashoutCount'
              width="160"
              :label="$t('EfficiencyAppr.LoanAmount')">
              </el-table-column>
          </el-table>
          <div class="pagination-container">
            <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="listQuery.page"
            :page-sizes="[5, 10, 20, 30]"
            :page-size="listQuery.limit"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
            </el-pagination>
          </div>
        </el-card>
    </div>
</template>

<script>
import { mapGetters } from "vuex";
import { getChannels } from "api/customQuery/index";
import { getPageAprove } from 'api/AuditReport/EfficiencyAppr/index'
export default {
  data() {
    return {
      define: '',
      startDatePicker: this.beginDate(),
      endDatePicker: this.processDate(),
      listLoading: false,
      total: null,
      listQuery: {
        limit: 5,
        page: 1,
        dateBegin: '',
        dateEnd: '',
        channel: '0'
      },
      appChannel: [
        {
          channel: '0',
          org_name: this.$t('rule.all')
        },
      ],
      tableData: [],
      multipleSelection: []
    };
  },
  computed: {
    ...mapGetters(["elements", "EfficiencyApprPage", 'getReportDefine'])
  },
  created() {
    if (this.EfficiencyApprPage.has(this.$route.path)) {
      this.listQuery = this.EfficiencyApprPage.get(this.$route.path)
    }
    this.getTime();
    // 渠道下拉
    getChannels().then(res => {
      this.appChannel = this.appChannel.concat(res.data)
      this.listQuery.channel = this.appChannel[0].channel;
      this.getList();
    });
    // 获取报表定义
    this.getReportDefine.forEach(item => {
      if (item.dictCode === 'APPROVAL_PROCESSING_EFFICIENCY') {
        this.define = item.dictValue
      }
    })
  },
  methods: {
    beginDate(){
      return {
        disabledDate(time){
          return time.getTime() < new Date('2019-05-27').getTime()//开始时间禁用5月28号之前的数据
        }
      }
    },
    processDate(){
      return {
        disabledDate(time){
          return time.getTime() < new Date('2019-05-27').getTime()//开始时间禁用5月28号之前的数据
        }
      }
    },
    getTime() {
      this.listQuery.dateBegin = this.GetDateStr(-7);
      this.listQuery.dateEnd = this.GetDateStr(0);
    },
    GetDateStr(AddDayCount) {
      let dd = new Date();
      dd.setDate(dd.getDate() + AddDayCount);// 获取AddDayCount天后的日期
      let y = dd.getFullYear();
      let m = (dd.getMonth() + 1) < 10 ? '0' + (dd.getMonth() + 1) : (dd.getMonth() + 1); // 获取当前月份的日期，不足10补0
      let d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate(); // 获取当前几号，不足10补0
      return y + '-' + m + '-' + d;
    },
    getList() {
      if (
        this.listQuery.dateBegin === "" ||
        this.listQuery.dateBegin === null ||
        this.listQuery.dateBegin === undefined
      ) {
        this.$message({
          showClose: true,
          type: "warning",
          message: this.$t("rule.ruleStartTime")
        });
      } else if (
        this.listQuery.dateEnd === "" ||
        this.listQuery.dateEnd === null ||
        this.listQuery.dateEnd === undefined
      ) {
        this.$message({
          showClose: true,
          type: "warning",
          message: this.$t("rule.ruleEndTime")
        });
      } else {
        this.listLoading = true;
        this.$store.dispatch('saveEfficiencyApprPage', { path: this.$route.path, listQuery: this.listQuery });
        getPageAprove(this.listQuery)
          .then(res => {
            if (res.status === 200) {
              this.listLoading = false;
              if (res.data.rows[0] !== null) {
                res.data.rows.forEach(item => {
                  if (item.crtTime !== '') {
                    item.crtTime = item.crtTime.substring(0, 10);
                  }
                })
                this.tableData = res.data.rows;
              } else {
                this.tableData = [];
              }
              this.total = Number(res.data.total);
            } else {
              this.$message({
                showClose: true,
                type: "warning",
                message: res.message
              });
            }
          })
      }
    },
    //查询
    search() {
      this.listQuery.page = 1;
      this.getList();
    },
    //重置
    reset() {
      this.listQuery.limit = 5;
      this.listQuery.page = 1;
      this.listQuery.dateBegin = this.GetDateStr(-7);
      this.listQuery.dateEnd = this.GetDateStr(0);
      this.listQuery.channel = '0';
    },
    //选中的数据
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      this.listQuery.limit = val;
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.page = val;
      this.getList()
    }
  }
};
</script>

<style scoped lang='scss'>
.box-card {
  width: 95%;
  margin-left: 2.5%;
  margin-right: 2.5%;
}
.title {
  line-height: 30px;
  font-size: 16px;
  display: flex;
  align-items: center;
  font-weight: bold;
}
.title:before{
  display: block;
  content: "";
  width: 3px;
  height: 16px;
  background-color: #309afe;
}
.title:before {
  margin-right: 8px;
}
::before {
  box-sizing: inherit;
  -webkit-tap-highlight-color: transparent;
}
.menu-title {
  width: 100%;
  box-sizing: border-box;
  background: #ffffff;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  .searchItem {
    display: flex;
    align-items: center;
    padding: 10px  0;
    span {
      display: inline-block;
      width: 100px;
      text-align: right;
      font-size: 12px;
      color: #5f5f61;
      padding-right: 5px;
    }
    div:nth-child(2) {
      width: 150px;
    }
  }
  .searchItem-date {
    display: flex;
    align-items: center;
    padding: 10px  0;
    b {
      margin: 0 10px;
      font-weight: normal;
      font-size: 12px;
      color: #5f5f61;
    }
    div {
       width: 150px;
    }
  }
}
.menu-title-btn {
  padding: 10px 0;
  box-sizing: border-box;
  margin-left: 20px;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
    &:nth-child(2) {
      background: #ebf5ff;
      color: #20a0ff;
      border: 1px solid #abd5ff;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
.menu-list {
  padding: 20px 0;
  box-sizing: border-box;
  button {
    padding: 0 20px;
    height: 28px;
    background: #20a0ff;
    color: #fff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
    margin-left: 10px;
    &:nth-child(1) {
      margin-left: 0;
    }
  }
  button[disabled] {
    padding: 0 20px;
    height: 28px;
    background: #c1e0ff;
    color: #fafbff;
    outline: none;
    border-width: 0;
    border-radius: 4px;
    font-size: 12px;
  }
}
.head-title2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.btns {
  display: inline-block;
  width: 24px;
  height: 24px;
  background-size: cover;
  background-image: url("../../../assets/images/question-mark.svg");
}
</style>